package com.example.bbcook;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import db.Ingrediente;
import db.IngredientiDataSource;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

	IngredientiDataSource datasource;

	ActionBar ab;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		/*datasource = new IngredientiDataSource(this);
		datasource.open();

		datasource.createIngrediente("BROCCOLI", "http://www.worldcommunitycookbook.org/season/guide/photos/broccoli.jpg", "verdura");
		datasource.createIngrediente("POMODORI PACHINO", "http://static.leonardo.it/wp-content/uploads/sites/13/2012/10/pomodoro-di-pachino.jpg", "verdura");
		List<Ingrediente> ingredienti = datasource.getAllIngredienti();*/

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		ActionBar actionBar = getSupportActionBar();
		//actionBar.setDisplayHomeAsUpEnabled(true);

		/*TextView t=(TextView)findViewById(R.id.textView1); 
		t.setText(ingredienti.get(1).getNome());

		ImageView imageView = (ImageView) this.findViewById(R.id.imageView1);
	    AssetManager am = getResources().getAssets();
	    InputStream is = null;
	    try {
	        is = am.open("broccoli.jpg");
	        // use the input stream as you want
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
        Drawable dImage = Drawable.createFromStream(is, "src name");

        imageView.setImageDrawable(dImage);*/
		/**/
		//imageView.setImageResource(R.drawable.broccoli);
		//imageView.setImageResource(R.drawable.broccoli);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.main_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}

	public void aggiungiIngrediente(View view){
		Intent intent = new Intent(this, SceltaIngredientiActivity.class);
		startActivity(intent);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle presses on the action bar items
		switch (item.getItemId()) {
		case R.id.action_search:
			openBasket();
			return true;
		case R.id.action_basket:
			openBasket();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	public void openBasket(){
		//Intent intent = new Intent(MainActivity.this, SecondaryActivity.class);
		//startActivity(intent);
		setContentView(R.layout.activity_main);		

	}
}